package servicedependencycircle;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import servicedependencycircle.ServiceDependencyCircleMatch;
import servicedependencycircle.ServiceDependencyCircleMatcherFactory;
import servicedependencycircle.ServiceDependencyCircleMatcher;

public class ServiceDependencyCircleConstraint extends Constraint<ServiceDependencyCircleMatch> {

	private ServiceDependencyCircleMatcherFactory matcherFactory;

	public ServiceDependencyCircleConstraint() {
		matcherFactory = new ServiceDependencyCircleMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "Service $service.name$ is involved in a dependency circle.";
	}

	@Override
	public EObject getLocationObject(ServiceDependencyCircleMatch signature) {
		Object location = signature.get("service");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("error");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<ServiceDependencyCircleMatch, ServiceDependencyCircleMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
